home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_100
/
133_01
/
e3
< prev
next >
Wrap
Text File
|
1985-03-09
|
5KB
|
269 lines
/*
e screen editor
(C) G. Nigel Gilbert, MICROLOGY, 1981
August-December 1981
FILE: e3
FUNCTIONS: putline,putoffset,putstatusline,putlineno,,putpage,
putmess,unmess,puts,rewrite,calcoffset,resetcursor
PURPOSE: write text to screen
*/
#include "e.h"
putline(line,y)
int line, y;
{
char *getline(), *p, c;
int cp, bright, lastcol, off, x, nblank;
deleteline(0,y);
if (line <= lastl) {
bright= !hilight || line == cline;
if (blocking && !bright) {
if (to) bright= (line >= from) && (line <= to);
else bright= (line >= (from > cline ? cline : from)) &&
(line <= (from > cline ? from : cline));
}
lastcol=SWIDTH;
off=x=0;
p=getline(line);
if ( (line == cline && calcoffset()) || (blockscroll && offset) ) {
lastcol+=offset-1;
off=offset;
x=1;
makedim();
putch('<');
makebright();
}
if (!bright) makedim();
for (cp=nblank=0; *p && cp < lastcol; p++) {
if (*p == '\t')
do {
if (cp >= off && cp < lastcol)
nblank++;
}
while (++cp % tabwidth);
else {
if (cp++ >= off) {
if (*p == ' ') nblank++;
else {
if (nblank) {
x+=nblank;
if (nblank < GOTOLEN)
for (; nblank; nblank--)
putch(' ');
else {
gotoxy(x,y);
nblank=0;
}
}
dispch(*p);
x++;
}
}
}
}
if (*p && y < SHEIGHT) {
if (bright) makedim();
else makebright();
gotoxy(SWIDTH,y);
putch('>');
}
makebright();
}
}
putoffset()
{
int i;
gotoxy(0,0);
if (offset) for(i=3-uspr(offset); i>0; i--) putch(' ');
else puts(" ");
gotoxy(0,cursory);
}
putstatusline(line)
int line;
{
deleteline(FNPOS,0);
makedim();
puts(filename);
putlineno(line);
makebright();
if (errmess != NULL) {
gotoxy(EMPOS,0);
puts(errmess);
}
}
putlineno(line)
int line;
{
int i;
if (!displaypos) return;
gotoxy(LNPOS,0);
makedim();
i=uspr(line);
putch(':');
for (i=8-i-uspr(cursorx+1); i > 0; i--) putch(' ');
makebright();
}
putpage() /*display page more or less centered about 'cline'*/
{
int y,line;
pfirst= loc(cline,(topline-SHEIGHT)/2);
plast = loc(pfirst,SHEIGHT-topline);
putstatusline(cline);
for (line=pfirst, y=topline; line <= plast; line++, y++) {
if (cline == line) {
cursory = y;
adjustc(cursorx);
}
putline(line, y);
}
if (y <= SHEIGHT) delpage(y);
}
putmess(message)
char *message;
{
int lines;
if (blankedmess && topline > blankedmess) {
gotoxy(3,blankedmess++);
puts(message);
return;
}
if (topline == (helpon ? HELPLINES : 1)) lines=2;
else lines=1;
if (cursory < (topline+=lines)) {
gotoxy(0,cursory);
for ( ; cursory < topline; cursory++) {
insertline();
if (plast != lastl) plast--;
}
}
else pfirst+= lines;
deleteline(0,topline-2);
deleteline(0,topline-1);
gotoxy(3,topline-2);
puts(message);
}
unmess()
{
int l, i, newtop, diff;
newtop= (helpon ? HELPLINES : 1);
if (!(diff=topline-newtop)) return;
if (diff < PAGEOVERLAP && pfirst-diff < 1) {
if (blankedmess == newtop) return;
for (l=newtop; l < topline; l++) deleteline(0,l);
blankedmess=newtop;
return;
}
blankedmess=NO;
if ((pfirst-=diff) < 1) {
topline=newtop;
putpage();
}
else {
for (l=newtop, i=0; l < topline; l++, i++) putline(pfirst+i,l);
topline=newtop;
}
}
puts(s) /*as usual, but turns text bright or dim as required*/
char *s;
{
int dim;
char c;
dim=NO;
while ( (c=*s++) )
switch(c) {
case BRIDIM :
(dim=!dim) ? begdim() : enddim();
break;
case '\n':
putch('\r');
default :
putch(c);
}
if (dim) enddim();
}
rewrite(cp,x) /*rewrites current line from char 'cp', col 'x', onwards*/
int cp, x;
{
int i, begmark;
char c;
begmark= (calcoffset() > 0);
i= x-offset+begmark;
deleteline((i>0 ? i : 0),cursory);
if (!x && begmark) {
begdim();
putch('<');
enddim();
}
while (x < SWIDTH+offset-begmark && (c=text[cp++])) {
if (c == '\t') {
for (i=tabwidth-x%tabwidth; i>0 && x<SWIDTH+offset-begmark; x++, i--)
if (x >= offset) putch(' ');
}
else if (x++ >= offset) dispch(c);
}
if (c && cursory < SHEIGHT) {
begdim();
putch('>');
enddim();
}
}
calcoffset() /*calculate horizontal screen offset required for
cursor to be on screen*/
{
for (offset=(!blockscroll || cursorx < lastoff ? 0 : lastoff);
cursorx >= SWIDTH+offset-(offset>0); offset+=OFFWIDTH);
return offset;
}
resetcursor() /*put cursor on current character, coping with
horizontal scroll */
{
int line, y;
if (lastoff != calcoffset()) {
if (blockscroll) {
for (line=pfirst, y=topline; line <= plast; line++, y++)
if (line != cline) putline(line,y);
}
putoffset();
rewrite(0,0);
lastoff=offset;
}
gotoxy(cursorx-offset+(offset>0),cursory);
}
(3,topline-2);
puts(message);
}
unmess()
{
int l, i, newtop, diff;